let app = new Vue({
    el: '#app',
    data:{
        inviteCode:'',
        phone:'',
        nickname:'',
        password:'',
        confirm:'',
        message:'',
        hasError: false
    },
    methods:{
        register:function(){
            let data = {
                inviteCode:this.inviteCode,
                phone:this.phone,
                nickname:this.nickname,
                password:this.password,
                confirm:this.confirm
            };
            //console.log("=======data=====:",data);
            if(data.password !== data.confirm){
                this.hasError = true;
                this.message = '确认密码不一致!';
                return;
            }

            $.ajax({
                url: '/register',
                method: 'POST',
                data: data,
                success:function(r){
                    //console.log(r);
                    if(r.code == CREATED){
                        app.hasError = false;
                        location.href = '/login.html?register'
                    }else{
                        app.hasError = true;
                        app.message = r.message;
                    }

                }

            })

        }

    }
})